package com.flipdf2.serialize.ppml;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;

import com.flipdf2.serialize.ppml.element.PPML;

public class PPMLFileProducer {
	public PPMLFileProducer() {
	}

	public void produce(File file, PPML ppml) throws IOException, PPMLException {
		ppml.check();

		XMLOutputter outputter = new XMLOutputter(org.jdom.output.Format
				.getPrettyFormat());
		FileOutputStream output = new FileOutputStream(file);
		outputter.output(createDocument(ppml), output);
		output.close();
	}

	private Document createDocument(PPML ppml) throws PPMLException {
		Document doc = new Document();

		Element root = ppml.toXML();
		doc.setRootElement(root);

		return doc;
	}
}
